package com.spark.lola.configuration;

import com.spark.lola.support.core.constant.RedisDatabase;
import com.spark.lola.support.redis.factory.TemplateConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;

/**
 * @Author: DengYeJun
 * @Date: 2019/3/14 0014 10:00
 */
@Configuration
public class RedisConfiguration {
    @Bean
    public RedisTemplate<String, String> systemRedis(TemplateConnectionFactory templateConnectionFactory,
                                                     Jackson2JsonRedisSerializer jackson2JsonRedisSerializer){
        RedisTemplate<String, String> template = new RedisTemplate<>();
        template.setConnectionFactory(templateConnectionFactory.createLettuceConnectionFactory(RedisDatabase.SYSTEM_DATABASE));
        template.setKeySerializer(jackson2JsonRedisSerializer);
        template.setValueSerializer(jackson2JsonRedisSerializer);
        return template;
    }

}
